package com.example.map.myapplication;

/**
 * Created by qundui on 2017/5/25.
 */

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class BookMarkerFragment1 extends Fragment {
MainActivity mainActivity;
    private Handler mhandler;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.bookmarker, container, false);
        initListView(view);
        return view;
    }

    @Override
    public void onAttach(Activity activity) {
      mainActivity= (MainActivity) activity;
        mhandler=mainActivity.getmHandler();
        super.onAttach(activity);
    }



    // 初始化listview
    public void initListView(View view) {
        ListView lv = (ListView) view.findViewById(R.id.listview);
        final List<String> list = new ArrayList<String>();
        list.add("baidu");
        list.add("腾讯");
        list.add("新浪");
        list.add("搜狐");
        ArrayAdapter adapter = new ArrayAdapter(
                BookMarkerFragment1.this.getActivity(), R.layout.mytext,
                R.id.text, list);
        lv.setAdapter(adapter);
        final Message m=Message.obtain();
        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                m.what=position;
                mhandler.sendMessage(m);
            }
        });


}

}